!function () {
    function e() {
    }

    function t(e, t) {
        var n = "string" == typeof e && e.indexOf(".") > 0, i = "string" == typeof t && t.indexOf(".") > 0;
        if (n && i) {
            var r = e.split("."), o = t.split(".");
            if (4 === r.length && 4 === o.length) {
                for (var a = 0; a < 4; a++) {
                    var v = +r[a], c = +o[a];
                    if (v > c)return 1;
                    if (v < c)return -1
                }
                return 0
            }
        } else {
            var f = +e, u = +t;
            if (f > 0 && u > 0)return f > u ? 1 : f == u ? 0 : -1
        }
    }

    function n() {
        var e, n, i = $.Deferred(), o = f(), a = o && o.version;
        return "string" == typeof a && a != d ? (e = t(a, "9.16.1658.0"), n = t(a, 50160931), e >= 0 || n >= 0 ? (h = a, r("qqlive://pullservice/atag=web.vplay", function (e) {
                    e ? i.resolve() : i.reject(-1)
                })) : i.reject(-3)) : i.reject(-2), i
    }

    function i(e, t, n, i) {
        function o() {
            n ? a() : v(e, function (e) {
                    e ? f.resolve() : a()
                })
        }

        function a() {
            i ? f.reject() : c(e, function (e) {
                    e ? f.resolve() : f.reject()
                })
        }

        var f = $.Deferred();
        return t ? o() : r(e, function (e) {
                e ? f.resolve() : o()
            }), f
    }

    function r(e, t) {
        var n = "undefined" != typeof txv.ua.ie;
        n ? o(e, t) : a(e, t)
    }

    function o(n, i) {
        var r = t(h, "9.16.1647.0"), o = t(h, 50160930);
        i = i || e, r >= 0 || o >= 0 ? !function () {
                try {
                    var e = new ActiveXObject("QQLive.Application");
                    e.OpenQQLive(n), i(!0)
                } catch (e) {
                    i(!1)
                }
            }() : i(!1)
    }

    function a(t, n) {
        if (n = n || e, 0 == $("#NPQQLive").length) {
            var i = '<embed id="NPQQLive" name="NPQQLive" width="1" height="1" type="application/tecent-qqlive-plugin" hidden="true" invokeurls="false"/>';
            $("body").append(i)
        }
        var r = document.getElementById("NPQQLive");
        if (r && r.OpenSSO)try {
            r.OpenSSO(t), n(!0)
        } catch (e) {
            n(!1)
        } else n(!1)
    }

    function v(n, i) {
        if (i = i || e, "http:" === location.protocol) {
            var r = !1;
            try {
                var o;
                o = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"), o.onreadystatechange = function () {
                    4 == o.readyState && (200 == o.status ? i(!0) : r || (r = !0, i(!1)))
                }, o.open("POST", "http://127.0.0.1:11066/startclient", !0), o.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"), o.send(n)
            } catch (e) {
                r || (r = !0, i(!1))
            }
        } else {
            var a = t(h, "9.18.1863.0"), v = t(h, 50161131);
            if (a >= 0 || v >= 0) {
                var c = new Image;
                c.onload = function () {
                    var e = (c.width, c.height);
                    i(1 == e && 1 == e)
                }, c.onerror = function () {
                    i()
                }, c.src = "http://127.0.0.1:11066/pullclientjpg?cmd=" + encodeURIComponent(n) + "&hash=" + Math.floor(1e6 * Math.random())
            } else i(!1)
        }
    }

    function c(e, t) {
        var n = $(window), i = !0, r = txv.ua.chrome > 0, o = !0, a = function (e) {
            i && (i = !1, t && t(e))
        }, v = function () {
            r && (o = !0)
        };
        r && (o = !1), n.bind("blur", v);
        var c = $('<iframe src="' + e + '">');
        c.hide(), $("body").append(c), setTimeout(function () {
            if (n.unbind("blur", v), c.remove(), a(o), !o) {
                var e = new Date;
                e.setTime(e.getTime() - 1), document.cookie = g + "=0; path=/; expires=" + e.toGMTString()
            }
        }, 1e3)
    }

    function f() {
        var e = "undefined" != typeof txv.ua.ie;
        return e ? u() : l()
    }

    function u() {
        try {
            var e = new ActiveXObject("QQLiveInstaller.InstallHelper.1"), t = e.GetVersionByClsid("D9EBCF5D-3F8F-4B6A-89BA-70577BE73C62");
            return {platform: "ie", version: t}
        } catch (e) {
            return {platform: "ie", version: d}
        }
    }

    function l() {
        for (var e = null, t = 0; t < navigator.plugins.length; t++)if ("QQLive" == navigator.plugins[t].name || "腾讯视频" == navigator.plugins[t].name || "npQQLive.dll" == navigator.plugins[t].filename) {
            e = navigator.plugins[t];
            break
        }
        var n = d;
        if (e)if ("undefined" != typeof e.version) n = e.version; else {
            var i;
            if (i = e.description.match(/version:((\d+\.){3}(\d+)?)/)) {
                n = i[1] || "";
                for (var r = n.split(".") || [], t = 0, o = r.length; t < o; t++) {
                    var a = parseInt(r[t]);
                    r[t] = "" + a
                }
                r.length > 1 && (n = r.join("."))
            }
        }
        return {platform: "webkit", version: n}
    }

    function s(e) {
        if (e) {
            txv.cookie.del(g);
            var t = new Date;
            t.setTime(t.getTime() + 31536e6), document.cookie = g + "=" + e + "; path=/; expires=" + t.toGMTString() + ";"
        }
    }

    function p(e) {
        if (e)if ("https:" === location.protocol) {
            var t = new Image;
            t.onload = function () {
                var n = t.width, i = t.height;
                if (n > 0 && i > 0) {
                    var r = 100 * (n - 1) + (i - 1) + 50160820;
                    e({version: r}), s(r)
                }
            }, t.onerror = function () {
                e()
            }, t.src = "http://127.0.0.1:11066/getversionjpg?hash=" + Math.floor(1e6 * Math.random())
        } else {
            var n = !1, i = function (t) {
                n || (n = !0, e())
            };
            $.ajax({
                url: "http://127.0.0.1:11066/getinfo",
                jsonpCallback: "qqliveclientinfo",
                dataType: "jsonp",
                timeout: 2e3,
                success: function (t) {
                    e({version: t.ver}), s(t._ver)
                },
                error: i
            });
            try {
                var r = document.getElementsByTagName("head")[0];
                if (r) {
                    var o = r.firstChild;
                    o && (o.onerror = i)
                }
            } catch (t) {
                e()
            }
        }
    }

    var d = "0.0.0.0", h = d, g = "QQLivePCVer", m = function (e, t, n) {
        var i = $.Deferred();
        if (h = d, !e) {
            var r = f() || {}, o = r.version;
            if ("string" == typeof o && o !== d) {
                var a = Number(o.replace(/\./gi, "")) || 0;
                if (a > 0)return h = o, i.resolve(o), i
            }
        }
        var v = function () {
            if (n) h = d, i.reject(); else {
                var e = +txv.cookie.get(g);
                e > 0 ? (h = e, i.resolve(e)) : (h = d, i.reject())
            }
        };
        return t ? v() : p(function (e) {
                e && e.version ? (h = e.version, i.resolve(e.version)) : v()
            }), i
    }, y = {exist: m, pull: n, open: i};
    txv.client = y
}();